package com.wanmait.movie.webController;

import com.wanmait.movie.entity.request.user.UserLoginRequest;
import com.wanmait.movie.entity.request.user.UserRegisterRequest;
import com.wanmait.movie.service.UserService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("web")
public class WebIndexController {
    @Resource
    private UserService userService;
    /**
     * 用户注册
     * @param userRegisterRequest 注册请求
     * @return 注册结果
     */
    @PostMapping("/register")
    public AjaxResult register(@RequestBody UserRegisterRequest userRegisterRequest){
        //注册信息不能为空
        if (userRegisterRequest == null){
           return AjaxResult.error(400,"用户注册信息为空");
        }
        return userService.register(userRegisterRequest);
    }

    /**
     * 登录方法
     * 接收用户登录请求并返回登录结果
     * @param userLoginRequest 用户登录请求对象
     * @param request HTTP请求对象
     * @return 登录结果
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request){
        // 登录信息不能为空
        if (userLoginRequest == null){
            return AjaxResult.error(400,"登录信息为空");
        }
        return userService.login(userLoginRequest,request);
    }
}
